package cn.webrx;

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class NumberFormat2 {
    public static void main(String[] args) {
        //DecimalFormat df = new DecimalFormat("#,###.###");
        DecimalFormat df = new DecimalFormat("0,000.###");
        //最多3位小数，如果没有小数，则没有
        df.setMaximumFractionDigits(3);
        //必须保留3位小数
        df.setMinimumFractionDigits(3);
        System.out.println(df.format(1023410.5678));
        System.out.println(df.format(2422424242.5678));
        System.out.println(df.format(10.0019));
        System.out.println(df.format(10));

    }
    public static void num2(String[] args) {
        //数字
        NumberFormat nf = NumberFormat.getInstance();
        System.out.println(nf.format(12414244289l));
        System.out.println(nf.format(124142442));

        nf.setMaximumFractionDigits(2);
        System.out.println(nf.format(124142442.1294566));

    }
    public static void p(String[] args) {
        //格式化百分比
        NumberFormat nf = NumberFormat.getPercentInstance();
        //小数精度位数
        nf.setMaximumFractionDigits(2);

        System.out.println(nf.format(1));//100%
        System.out.println(nf.format(1d));//100%
        System.out.println(nf.format(1f));//100%
        System.out.println(nf.format(.516578234242));//56.66%
    }
}
